public class UT_Case_Trigger{
/*
    static testMethod void Case_Trigger_Test(){
        Case c;
        
        // New Case Insert
        c = New Case();
        c.Status = 'Waiting';
        c.Priority = 'High';
        Entitlement__c[] e_1 = [select Id from Entitlement__c];
        if(e_1.size()>0){
            c.Entitlement__c = e_1[0].Id;
            c.Origin  = 'Web';
            c.Entitled_First_Response__c=system.now().addHours(3);
            c.Entitled_Workaround_Time__c=system.now().addHours(4);
            c.Entitled_Resolve_Time__c=system.now().addHours(5);
            Insert c;
        }
            
        // StopClock [Priority changed, status unchanged, old status is stop], valid
        c = GetStoppedCase(True);
        if(c!=null){
            if(c.Priority == 'High'){
                c.Priority = 'Low';
            }
            else{
                c.Priority = 'High';
            }
            c.Entitled_First_Response__c = System.now().addHours(5);
            c.Entitled_Workaround_Time__c = System.now().addHours(10);
            c.Entitled_Resolve_Time__c = System.now().addHours(15);
            update c;   
        }
        
        // StopClock [Priority changed, status unchanged, old status is stop], invalid
        c = GetStoppedCase(True);
        if(c!=null){
            if(c.Priority == 'High'){
                c.Priority = 'Low';
            }
            else{
                c.Priority = 'High';
            }

            //        c.setFieldsToNull(new String[] {'Entitled_First_Response__c'});
            //        c.setFieldsToNull(new String[] {'Entitled_Workaround_Time__c'});
            //        c.setFieldsToNull(new String[] {'Entitled_Resolve_Time__c'});
            
            c.Entitled_First_Response__c = null;
            c.Entitled_Workaround_Time__c = null;
            c.Entitled_Resolve_Time__c = null;
            try{
                update c;
            }
            catch (Exception e){}
        }

        // StopClock [Priority changed, startstop mode changed], valid
        c = GetRunningCase(True);
        if(c!=null){
                        
            if(c.Priority == 'High'){
                c.Priority = 'Low';
            }
            else{
                c.Priority = 'High';
            }
            c.Status = 'Pending';
            c.Entitled_First_Response__c = System.now().addHours(5);
            c.Entitled_Workaround_Time__c = System.now().addHours(10);
            c.Entitled_Resolve_Time__c = System.now().addHours(15);
            update c;   
        }

        // StopClock [Priority changed, startstop mode changed], invalid
        c = GetRunningCase(True);
        if(c!=null){
            if(c.Priority == 'High'){
                c.Priority = 'Low';
            }
            else{
                c.Priority = 'High';
            }
            c.Status = 'Pending';
            c.Entitled_First_Response__c = null;
            c.Entitled_Workaround_Time__c = null;
            c.Entitled_Resolve_Time__c = null;
            try{
                update c;
            }
            catch (Exception e){}
        }

        // StartClock (Priority unchanged, startstop mode changed), valid
        c = GetStoppedCase(True);
        if(c!=null){
            c.Status = 'New';
            c.Remaining_First_Response__c = 180;
            c.Remaining_First_Workaround__c = 240;
            c.Remaining_Resolve_Time__c = 300;
            update c;       
        }
        
        // StartClock (Priority unchanged, startstop mode changed), invalid
        c = GetStoppedCase(True);
        if(c!=null){
            c.Status = 'New';
            c.Remaining_First_Response__c = null;
            c.Remaining_First_Workaround__c = null;
            c.Remaining_Resolve_Time__c = null;
            try{
                update c;
            }
            catch (Exception e){}       
        }

        // StopClock (Priority unchanged, startstop mode changed), valid
        c = GetRunningCase(True);
        if(c!=null){
            c.Status = 'Pending';
            c.Entitled_First_Response__c = System.now().addHours(5);
            c.Entitled_Workaround_Time__c = System.now().addHours(10);
            c.Entitled_Resolve_Time__c = System.now().addHours(15);
            update c;       
        }

        // StopClock (Priority unchanged, startstop mode changed), invalid
        //c = [select Id, Status, Priority from Case where (Status != 'Pending' and Status != 'Waiting') and Entitlement__c!=null limit 1];
        c = GetRunningCase(True);
        if(c!=null){
            c.Status = 'Pending';
            c.Entitled_First_Response__c = null;
            c.Entitled_Workaround_Time__c = null;
            c.Entitled_Resolve_Time__c = null;
            try{
                update c;
            }
            catch (Exception e){}       
        }    
    }
    
    public static Case getStoppedCase(Boolean havingEnt){
        Case[] c;
        if(havingEnt==True)
            c = 
        else
            c = 
        if(c.size()>0)
            return c[0];
        else
            return null;
    }
    
    public static Case getRunningCase(Boolean havingEnt){
        Case[] c;
        if(havingEnt==True)
            c = 
        else
            c = 
        if(c.size()>0)
            return c[0];
        else
            return null;
        
    }
    
    public static testMethod void testGetRunningCase() {
        Case c = getRunningCase(true);
        c = getRunningCase(false);
    }
    
    public static testMethod void testGetStoppedCase() {
        Case c = getStoppedCase(true);
        c = getStoppedCase(false);
    }
*/   
    //
    // Work out the OnCase triggers
    //
    public static testMethod void testSimpleInsert() {
        Case c = new Case(Subject='TEST CASE INSERT');
        insert c;
    }
    
    public static testMethod void testBulkInsert() {
    	UT_SObjectFactory.InterconnectedSObjectsForMASP o = new UT_SObjectFactory.InterconnectedSObjectsForMASP(1);
    	Entitlement__c defEnt = o.addDefEnt();
    	
    	// We still do Case Pack updates one at a time :-(
    	//update (new Entitlement__c(Id=defEnt.Id, Cases_Remaining__c=200,Case_Pack__c=True,Renewal_Amount__c=200));
    	
        Case[] cBatch = new List<Case>();
        while (cBatch.size() < 100) {
        	cBatch.add(new Case( 
        		Subject='CASE INSERT', ContactId=o.c.Id ));
        }
        
        // Run the insert trigger many times
        System.debug('\n\n BULK TEST \n\n  Before bulk insert:  ' + Limits.getQueries() + ' queries\n\n\n' );
        insert cBatch;
        System.debug('\n\n BULK TEST \n\n  After bulk insert:  ' + Limits.getQueries() + ' queries\n\n\n' );
        
        System.assert(20 >= Limits.getQueries(),'Max 20 queries in trigger context');
    }
 
    public static testMethod void testSimpleUpdate() {
        Case[] c = [select Id,Status from Case limit 1];
        if (c.size()>0) {
            c[0].Status = c[0].Status + 'xyz';
            update c;
        }
    }

}